package net.ghsoft
{
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	
	import spark.components.Group;
	
	import net.ghsoft.ConvertGlobal;
	import net.ghsoft.Convert.*;
	
	[Event(name="change", type="flash.events.Event")]

	public class USBGlobal extends Group
	{
		private static var _JNowData:Object = null;				
		private static var _JNowWeatherData:Object = null;		
		private static var _JNowWeatherTime:Object = null;		
		
		private var _NowData:String = "";		
		public function set NowData(value:String):void
		{
			_NowData = value;
			_JNowData = JSON.parse(value);
			if(_JNowData.length > 0)
			{
				_JNowWeatherData = _JNowData[0];
			}
			if(_JNowData.length > 1)
			{
				_JNowWeatherTime = _JNowData[1];
			}

			dispatchEvent(new Event("change"));
		}
		
		public function get NowData():String
		{
			return _NowData;
		}
		
		/** 
		 * 获取当前温度
		 * */
		public function get NowTemperature():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherData.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherData.length; index ++)
				{
					if(_JNowWeatherData[index].hasOwnProperty("Temperature"))
					{
						result.addItem(ConvertTemperature.getLocalTemperature(
							Number(_JNowWeatherData[index]["Temperature"])));
					}	
				}
			}		
			return result;
		}
		
		/** 
		 * 获取当最大温度
		 * */
		public function get TemperatureMax():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherTime.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherTime.length; index ++)
				{
					if(_JNowWeatherTime[index].hasOwnProperty("TemperatureMax"))
					{
						result.addItem(ConvertTemperature.getLocalTemperature(
							Number(_JNowWeatherTime[index]["TemperatureMax"])));
					}	
				}
			}		
			return result;
		}
		
		
		/** 
		 * 获取当最大温度时间
		 * */
		public function get TemperatureMaxTime():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherTime.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherTime.length; index ++)
				{
					if(_JNowWeatherTime[index].hasOwnProperty("TemperatureMaxTime"))
					{
						result.addItem(ConvertGlobal.DateTime2SystemString(
							ConvertGlobal.CString2Date(_JNowWeatherTime[index]["TemperatureMaxTime"].toString())));
					}	
				}
			}		
			return result;
		}
		
		/** 
		 * 获取当最小温度
		 * */
		public function get TemperatureMin():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherTime.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherTime.length; index ++)
				{
					if(_JNowWeatherTime[index].hasOwnProperty("TemperatureMin"))
					{
						result.addItem(ConvertTemperature.getLocalTemperature(
							Number(_JNowWeatherTime[index]["TemperatureMin"])));
					}	
				}
			}		
			return result;
		}
		
		
		/** 
		 * 获取当最小温度时间
		 * */
		public function get TemperatureMinTime():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherTime.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherTime.length; index ++)
				{
					if(_JNowWeatherTime[index].hasOwnProperty("TemperatureMinTime"))
					{
						result.addItem(ConvertGlobal.DateTime2SystemString(
							ConvertGlobal.CString2Date(_JNowWeatherTime[index]["TemperatureMinTime"].toString())));
					}	
				}
			}		
			return result;
		}
		

		
		/** 
		 * 获取当前湿度
		 * */
		public function get NowHumidity():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherData.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherData.length; index ++)
				{
					if(_JNowWeatherData[index].hasOwnProperty("Humidity"))
					{
						result.addItem(Number(_JNowWeatherData[index]["Humidity"]));
					}	
				}
			}		
			return result;
		}
		
		/** 
		 * 获取当前雨量
		 * */
		public function get NowRain():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherData.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherData.length; index ++)
				{
					if(_JNowWeatherData[index].hasOwnProperty("Rain"))
					{
						result.addItem(ConvertRain.getLocalRain(
							Number(_JNowWeatherData[index]["Rain"])));
					}	
				}
			}		
			return result;
		}
		
		/** 
		 * 获取当前风速
		 * */
		public function get NowWind():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherData.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherData.length; index ++)
				{
					if(_JNowWeatherData[index].hasOwnProperty("Wind"))
					{
						result.addItem(Number(_JNowWeatherData[index]["Wind"]));
					}	
				}
			}		
			return result;
		}
		
		/** 
		 * 获取当前气压
		 * */
		public function get NowBarometer():ArrayCollection
		{
			var result:ArrayCollection = new ArrayCollection();
			
			if(_JNowWeatherData.length > 0)
			{
				for(var index:int = 0;index < _JNowWeatherData.length; index ++)
				{
					if(_JNowWeatherData[index].hasOwnProperty("Barometer"))
					{
						result.addItem(ConvertBarometer.getLocalBarometer(
							Number(_JNowWeatherData[index]["Barometer"])));
					}	
				}
			}		
			return result;
		}


	}
}